# 基础jdk镜像
FROM adoptopenjdk/openjdk8:jdk8u312-b07-slim

# 查看下jdk版本
RUN ["java", "-version"]
# 查看java在哪里
RUN ["whereis", "java"]

# 镜像构建时候，指定nacos版本
ARG NACOS_VERSION=2.0.3
LABEL "official website"="https://github.com/alibaba/nacos" \
      "official docker website"="https://github.com/nacos-group/nacos-docker" \
      "description"="仿照官网自制nacos-server-$NACOS_VERSION" \
      "maintainer"="_blank"

RUN ["echo", "\"https://github.com/alibaba/nacos/releases/download/$NACOS_VERSION/nacos-server-$NACOS_VERSION.tar.gz\""]
RUN ["echo", "\"https://github.com/nacos-group/nacos-docker/blob/v$NACOS_VERSION/build/bin/docker-startup.sh\""]

# set environment
ENV MODE="standalone" \
    PREFER_HOST_MODE="ip"\
    BASE_DIR="/opt/nacos" \
    CLASSPATH=".:$BASE_DIR/conf:$CLASSPATH" \
    CLUSTER_CONF="$BASE_DIR/conf/cluster.conf" \
    FUNCTION_MODE="all" \
    NACOS_USER="nacos" \
    JAVA="/opt/java/openjdk/bin/java" \
    JVM_XMS="1g" \
    JVM_XMX="1g" \
    JVM_XMN="512m" \
    JVM_MS="128m" \
    JVM_MMS="320m" \
    NACOS_DEBUG="n" \
    TOMCAT_ACCESSLOG_ENABLED="false" \
    TZ="Asia/Shanghai"

# 指定当前镜像的工作目录
WORKDIR $BASE_DIR

RUN ["cat", "/etc/passwd"]

ADD nacos-server-$NACOS_VERSION.tar.gz ./../

ADD --chown=502:dialout docker-startup.sh $BASE_DIR/bin

#RUN ["adduser", "nacos"]
#RUN ["addgroup", "nacos"]
#RUN ["adduser", "nacos", "nacos"]
## 授权 https://best.practices.cloud/2019/06/26/Dockerfile%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5.html
## 由于dockerfile构建镜像使用的是分层只读文件系统，如果使用 chown 更改一个大目录权限，相当于复制了这个目录下所有文件，会导致镜像体积变大。
#RUN ["chown", "-R", "1000:1000", "/opt/nacos"]
#
#USER 1000:1000

RUN ["/bin/bash", "-c", "ls -alh $BASE_DIR/../"]
RUN ["/bin/bash", "-c", "ls -alh $BASE_DIR"]
RUN ["/bin/bash", "-c", "ls -alh $BASE_DIR/bin"]

RUN ["id"]
RUN ["cat", "/etc/passwd"]

EXPOSE 8848
ENTRYPOINT ["bin/docker-startup.sh"]

#docker build --no-cache -t nacos-server:2.0.3 -f Dockerfile .
#docker run -d -p 8848:8848 --name my-nacos-server dea3f34d9ada
#docker run -d --name nacos-server-standalone --network host -e MODE="standalone" c0c4afe2dcad

# see https://docs.docker.com/engine/reference/builder/

# see redis dockerfile https://github.com/docker-library/redis/blob/a04a6df0a4/6.2/Dockerfile
# see tomcat dockerfile https://github.com/docker-library/docs/blob/master/tomcat/README.md
# see tomcat dockerfile https://github.com/docker-library/tomcat/tree/025e9753a0/9.0/jdk8
# see nacos.slim dockerfile https://github.com/nacos-group/nacos-docker/blob/v2.0.3/build/Dockerfile.Slim
# see adoptopenjdk dockerfile https://github.com/AdoptOpenJDK/openjdk-docker/tree/master/8/jdk